<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>demangle</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Chapter 1. Boost.Core">
<link rel="up" href="../index.html" title="Chapter 1. Boost.Core">
<link rel="prev" href="default_allocator.html" title="default_allocator">
<link rel="next" href="empty_value.html" title="empty_value">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="default_allocator.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="empty_value.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="core.demangle"></a><a class="link" href="demangle.html" title="demangle">demangle</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="demangle.html#core.demangle.header_boost_core_demangle_hpp">Header
      &lt;boost/core/demangle.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="demangle.html#core.demangle.acknowledgments">Acknowledgments</a></span></dt>
</dl></div>
<div class="simplesect">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm46136450216176"></a>Authors</h3></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
          Peter Dimov
        </li>
<li class="listitem">
          Andrey Semashev
        </li>
</ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="core.demangle.header_boost_core_demangle_hpp"></a><a class="link" href="demangle.html#core.demangle.header_boost_core_demangle_hpp" title="Header &lt;boost/core/demangle.hpp&gt;">Header
      &lt;boost/core/demangle.hpp&gt;</a>
</h3></div></div></div>
<p>
        The header <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">demangle</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
        defines several tools for undecorating symbol names.
      </p>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.demangle.header_boost_core_demangle_hpp.synopsis"></a><a class="link" href="demangle.html#core.demangle.header_boost_core_demangle_hpp.synopsis" title="Synopsis">Synopsis</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span>
<span class="special">{</span>

<span class="keyword">namespace</span> <span class="identifier">core</span>
<span class="special">{</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">demangle</span><span class="special">(</span> <span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*</span> <span class="identifier">name</span> <span class="special">);</span>

    <span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*</span> <span class="identifier">demangle_alloc</span><span class="special">(</span> <span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*</span> <span class="identifier">name</span> <span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
    <span class="keyword">void</span> <span class="identifier">demangle_free</span><span class="special">(</span> <span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*</span> <span class="identifier">demangled_name</span> <span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>

    <span class="keyword">class</span> <span class="identifier">scoped_demangled_name</span>
    <span class="special">{</span>
    <span class="keyword">public</span><span class="special">:</span>
        <span class="keyword">explicit</span> <span class="identifier">scoped_demangled_name</span><span class="special">(</span> <span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*</span> <span class="identifier">name</span> <span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
        <span class="special">~</span><span class="identifier">scoped_demangled_name</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
        <span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*</span> <span class="identifier">get</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>

        <span class="identifier">scoped_demangled_name</span><span class="special">(</span> <span class="identifier">scoped_demangled_name</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="special">)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>
        <span class="identifier">scoped_demangled_name</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">=</span> <span class="special">(</span> <span class="identifier">scoped_demangled_name</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="special">)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>
    <span class="special">};</span>
<span class="special">}</span>

<span class="special">}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.demangle.header_boost_core_demangle_hpp.conventional_interface"></a><a class="link" href="demangle.html#core.demangle.header_boost_core_demangle_hpp.conventional_interface" title="Conventional interface">Conventional
        interface</a>
</h4></div></div></div>
<p>
          The function <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">demangle</span></code> is the conventional way to obtain
          demangled symbol name. It takes a mangled string such as those returned
          by <code class="computeroutput"><span class="keyword">typeid</span><span class="special">(</span><span class="identifier">T</span><span class="special">).</span><span class="identifier">name</span><span class="special">()</span></code> on certain implementations such as <code class="computeroutput"><span class="identifier">g</span><span class="special">++</span></code>,
          and returns its demangled, human-readable, form. In case if demangling
          fails (e.g. if <code class="computeroutput"><span class="identifier">name</span></code> cannot
          be interpreted as a mangled name) the function returns <code class="computeroutput"><span class="identifier">name</span></code>.
        </p>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="core.demangle.header_boost_core_demangle_hpp.conventional_interface.example"></a><a class="link" href="demangle.html#core.demangle.header_boost_core_demangle_hpp.conventional_interface.example" title="Example">Example</a>
</h5></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">demangle</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">typeinfo</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">X</span>
<span class="special">{</span>
<span class="special">};</span>

<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
    <span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*</span> <span class="identifier">name</span> <span class="special">=</span> <span class="keyword">typeid</span><span class="special">(</span> <span class="identifier">X</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">).</span><span class="identifier">name</span><span class="special">();</span>

    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">name</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// prints 1XIiE</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">demangle</span><span class="special">(</span> <span class="identifier">name</span> <span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// prints X&lt;int&gt;</span>
<span class="special">}</span>
</pre>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.demangle.header_boost_core_demangle_hpp.low_level_interface"></a><a class="link" href="demangle.html#core.demangle.header_boost_core_demangle_hpp.low_level_interface" title="Low level interface">Low
        level interface</a>
</h4></div></div></div>
<p>
          In some cases more low level interface may be desirable. For example:
        </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              Assuming that symbol demangling may fail, the user wants to be able
              to handle such errors.
            </li>
<li class="listitem">
              The user needs to post-process the demangled name (e.g. remove common
              namespaces), and allocating a temporary string with the complete demangled
              name is significant overhead.
            </li>
</ul></div>
<p>
          The function <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">demangle_alloc</span></code> performs name demangling
          and returns a pointer to a string with the demangled name, if succeeded,
          or <code class="computeroutput"><span class="keyword">nullptr</span></code> otherwise. The
          returned pointer must be passed to <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">demangle_free</span></code>
          to reclaim resources. Note that on some platforms the pointer returned
          by <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">demangle_alloc</span></code> may refer to the string
          denoted by <code class="computeroutput"><span class="identifier">name</span></code>, so this
          string must be kept immutable for the whole life time of the returned pointer.
        </p>
<p>
          The <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">scoped_demangled_name</span></code> class is a scope
          guard that automates the calls to <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">demangle_alloc</span></code>
          (on its construction) and <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">demangle_free</span></code>
          (on destruction). The string with the demangled name can be obtained with
          its <code class="computeroutput"><span class="identifier">get</span></code> method. Note that
          this method may return <code class="computeroutput"><span class="keyword">nullptr</span></code>
          if demangling failed.
        </p>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="core.demangle.header_boost_core_demangle_hpp.low_level_interface.example"></a><a class="link" href="demangle.html#core.demangle.header_boost_core_demangle_hpp.low_level_interface.example" title="Example">Example</a>
</h5></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">demangle</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">typeinfo</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">X</span>
<span class="special">{</span>
<span class="special">};</span>

<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
    <span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*</span> <span class="identifier">name</span> <span class="special">=</span> <span class="keyword">typeid</span><span class="special">(</span> <span class="identifier">X</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">).</span><span class="identifier">name</span><span class="special">();</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">scoped_demangled_name</span> <span class="identifier">demangled</span><span class="special">(</span> <span class="identifier">name</span> <span class="special">);</span>

    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">name</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// prints 1XIiE</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="special">(</span><span class="identifier">demangled</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">?</span> <span class="identifier">demangled</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">:</span> <span class="string">"[unknown]"</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// prints X&lt;int&gt;</span>
<span class="special">}</span>
</pre>
</div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="core.demangle.acknowledgments"></a><a class="link" href="demangle.html#core.demangle.acknowledgments" title="Acknowledgments">Acknowledgments</a>
</h3></div></div></div>
<p>
        The implementation of <code class="computeroutput"><span class="identifier">core</span><span class="special">::</span><span class="identifier">demangle</span></code>
        was taken from <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">exception</span><span class="special">/</span><span class="identifier">detail</span><span class="special">/</span><span class="identifier">type_info</span><span class="special">.</span><span class="identifier">hpp</span></code>, which in turn was adapted from <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">units</span><span class="special">/</span><span class="identifier">detail</span><span class="special">/</span><span class="identifier">utility</span><span class="special">.</span><span class="identifier">hpp</span></code> and <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">log</span><span class="special">/</span><span class="identifier">utility</span><span class="special">/</span><span class="identifier">type_info_wrapper</span><span class="special">.</span><span class="identifier">hpp</span></code>.
      </p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2014 Peter Dimov<br>Copyright © 2014 Glen Fernandes<br>Copyright © 2014 Andrey Semashev<p>
        Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost
        Software License, Version 1.0</a>.
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="default_allocator.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="empty_value.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
